﻿var Container;

/*弹出登陆回调*/
function AlertLoginReturn() {
    checklogin();
    HideWindow();
    if (typeof (top.frames["hotelReviews"]) != "undefined") {
        top.frames["hotelReviews"].location.reload();
        top.frames["hotelQuestions"].location.reload();
    }
}

function hbooking(url) {
    if (GetCookie('username') != '') { location = url; return; }
    ShowWindow('', '', webpath + 'BookingLogin.aspx?Page=' + URLencode(url));
}
function GetRoom(Obj, tm1, tm2) {
    if (!Obj) { Obj = Container; } else { Container = Obj } //容器
    if (!tm1) { tm1 = ''; } //入住时间
    if (!tm2) { tm2 = ''; } //离店时间
    var SL = parseInt(Obj.attr('s'));
    if (SL == NaN) SL = 0; //显示列数
    //拼写酒店ID
    var HID = '';
    $(Obj).each(function () {
        HID += ',' + $(this).attr('hid');
    });
    if (HID == '') return;
    if (HID != '') HID = HID.substring(1);
	
    var ajaxpath = webpath + 'sys/ajax/hotel/Room.ashx?hid=' + HID + '&tm1=' + tm1 + '&tm2=' + tm2;
    $.ajax({
        type: 'GET', cache: false,
        url: ajaxpath,
        dataType: 'xml',
        success: function (xml) {
            $(Obj).each(function () {
                var thisHID = $(this).attr('hid');
                var te = '';
                var children;
                var hCount = 0;
                $(xml).find('rooms>room[r_hotelid="' + thisHID + '"]').each(function () {
                    var t = '', o = null;
                    var ta = $(this).attr('r_picid');
                    if (ta != '' && $(xml).find('rooms>pic').length > 0) {
                        ta = ta.split(',');
                        for (var i = 0; i < ta.length; i++) { t += ',[p_id="' + ta[i] + '"]'; }
                        if (t != '') o = $(xml).find(t.substring(1));
                    }
					 te += '<dl class="clearfix">';
					 te += '	<dd class="row1"><a href="javascript:" class="closed">' + $(this).attr('r_name') + '<i></i></a></dd>';
					 te += '	<dd class="row3" style="width:50px;"><i>' + $(this).attr('r_internet') + '</i></dd>';
					 te += '	<dd class="row4"><del>&yen;' + $(this).attr('r_rackrate') + '</del></dd>';
					 te += '  	<dd class="row5">';
					 te += '	  <em>&yen;' + ($(this).attr('averageprice') == 0 ? $(this).attr('r_price') : $(this).attr('averageprice')) + '</em>';
					 te += ' 	  <div class="discountInfo">';
					 te += '		<ul class="clearfix">';
					 te += '			<li class="tips" style="z-index: 1;">';
					 te += '				<div class="text bonus"><b>返</b><em>&yen;' + $(this).attr('r_bonus') + '</em></div>';
					 te += '				<div class="hoverTip">';
					 te += '					<div class="box">';
					 te += '						<p>成功预订此产品点评后可获得<em> ' + $(this).attr('r_bonus') + ' </em>' + webconfig().bonusunits + webconfig().bonusname + '。</p>';
					 te += '						<b class="arrow">&nbsp;</b>';
					 te += '					</div>';
					 te += '				</div>';
					 te += '			</li>';
					 te += '			<li class="tips" style="z-index: 1;">';
					 te += '				<div class="text bonus"><b>抵</b><em>&yen;' + $(this).attr('r_diyong') + '</em></div>';
					 te += '				<div class="hoverTip">';
					 te += '					<div class="box">';
					 te += '						<p>成功预订此产品可抵扣<em> ' + $(this).attr('r_diyong') + ' </em>' + webconfig().bonusunits + webconfig().bonusname + '。</p>';
					 te += '						<b class="arrow">&nbsp;</b>';
					 te += '					</div>';
					 te += '				</div>';
					 te += '			</li>';
					 if ($(this).find('p').length) {
					 te += '			<li class="tips" style="z-index: 1;">';
					 te += '				<div class="text"><b>惠</b></div>';
					 te += '				<div class="hoverTip">';
					 te += '					<div class="box">';
						
							$(this).find('p').each(function () {
							te += '<p>'+$(this).text()+'</p>';
							});
					 te += '						<b class="arrow">&nbsp;</b>';
					 te += '					</div>';
					 te += '				</div>';
					 te += '			</li>';
					 }
					 te += '		</ul>';
					 te += '	 </div>';
					 te += ' </dd>';
					 te += '<dd class="row2">';
					 if ($(this).attr('r_paytype') == '0'){
						 if ($(this).attr('r_deposit') == '100'){
							 te += '	在线支付';
						 }else if($(this).attr('r_deposit') == '0'){
							 te += '	前台支付';
						 }else {
							 te += '	定金支付';
						 }
					 }else if($(this).attr('r_paytype') == '1'){
						if ($(this).attr('r_deposit') == $(this).attr('r_price')){
							 te += '	在线支付';
						 }else if($(this).attr('r_deposit') == '0'){
							 te += '	前台支付';
						 }else {
							 te += '	定金支付</dd>';
						 }
					 }
					 te += ' </dd>';
					 te += '	<dd class="row6">';
					  if ($(this).attr('averageprice') == '0') {
                        te += '		<a href="javascript:;" class="btn none">已 满</a>';
                    } else if ($(this).attr('day') != $(this).attr('days')) {
                        te += '<a onclick="hbooking(\'' + $(this).attr('bookingurl') + '\');" href="javascript:;" class="btn">部分满</a>';
                    } else {
                        te += '<a onclick="hbooking(\'' + $(this).attr('bookingurl') + '\');" href="javascript:;" class="btn">预 订</a>';
                    }
					 te += '	</dd>';
					 te += '</dl>';
					 te += '<ul class="roomRowson clearfix">';
					 te += '	<li>房型：' + $(this).attr('r_name') + '</li> ';
					 te += '	<li>面积：' + $(this).attr('r_area') + '平方米</li>';
					 te += '	<li>窗户：' + $(this).attr('r_windows') + '</li>';
					 te += '	<li>床型：' + $(this).attr('r_bedcategory') + '</li>';
					 te += '	<li>早餐：' + $(this).attr('r_breakfast') + '</li>';
					 te += '	<li>卫浴：' + $(this).attr('r_bathroom') + '</li>';
                     if (parseInt($(this).attr('r_addbed')) > 0) te += '<li>加床：可加床</li>';
					 if ($(this).attr('r_floor') != '') te += '<li>楼层：' + $(this).attr('r_floor') + '层</li>';
					 
					 te += '	<li class="pic">';
						if (o != null) {
							o.each(function () {
								//                            te += '<li><p><img src="' + formatpic($(this).attr('p_pic'), 'b') + '" height="75"></p></li>';
							    te += '<a rel="' + formatpic($(this).attr('p_pic'), 'e') + '" class="preview" title=""><img src="' + formatpic($(this).attr('p_pic'), 'b') + '" width="89" height="67" alt="' + $(this).attr('p_title') + '"/></a>';
							});
						}
					 te += ' </li>';
					 te += '</ul>';
					

                    hCount++;
                });
				
				var strHead = '<dl class="title clearfix"><dd class="row1">酒店房型</dd><dd class="row3" style="width:50px;">宽带</dd><dd class="row4">门市价</dd><dd class="row5">优惠价</dd><dd class="row2">支付方式</dd></dl>';
				
				var strfoot = '<div class="moreBox"><span class="open">查看全部房型</span></div>';
				
                if (te != '') {
                    $(this).html(strHead + te + strfoot);
                } else {
                    $(this).html(strHead + '<span>暂无房型</span>');
                }
                var has = $('.roomRowson').find('.pic');
                if (!$(has).find('img').length == 0 ) {
                    $(has).parents('.roomList').find('.row1').addClass('has');
                };
				$('.tips').hover( //下拉文字提示
					function(){
						$(this).css({'z-index': 100}).find('.hoverTip').show();
					},function(){
						$('.tips').css({'z-index': 1});
						$(this).find('.hoverTip').hide();
					}
				);
            });

            $('.roomList').each(function () { //酒店房型循环增加隐藏的样式
				if($(this).hasClass('showRoom')){
					$(this).find('.moreBox').hide();
				}else{
					$(this).find('dl').each(function (i) {
						if (i > 3) { 
							$(this).parent().find('.moreBox').show();
							$(this).addClass('rooms').hide();
						}
					});
				}
			});
			$('.roomList .closed').click(function(){//房型更多
				if($(this).hasClass('closed')){
					$(this).removeClass('closed');
					$(this).addClass('open');
					$(this).parents('dl').next('.roomRowson').slideDown();
				}else{
					$(this).addClass('closed');
					$(this).removeClass('open');
					$(this).parents('dl').next('.roomRowson').slideUp();
				}
			});
            $('.moreBox span').click(function(){//酒店房型更多
				if($(this).hasClass('open')){
					$(this).removeClass('open');
					$(this).parents('.roomList').find('.rooms').show();
				}else{
					$(this).addClass('open');
					$(this).parents('.roomList').find('.rooms').hide();
				}
			});
        }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.responseText); }
    });
}
function menu(t) {
    var img = $(t).find('img');
    if ($(img).attr('src').indexOf('open.gif') == -1) {
        $(img).attr('src', $(img).attr('src').replace('close.gif', 'open.gif'));
        $(t).siblings().show();
    } else {
        $(img).attr('src', $(img).attr('src').replace('open.gif', 'close.gif'));
        $(t).siblings().hide();
    }
}
function hotelsearch(p) {
    var t1 = $('#tm1').val(), t2 = $('#tm2').val(), d = new Date(), c = $('#cid').val(), t = $('#tid').val();
    if (c == 0) { alert('请选择地区！'); return false; }
    if (!t) t = 0;
    var url = '';
    var s = $('#p1').val();
    if (s) url += '&p1=' + s;
    s = $('#p2').val();
    if (s) url += '&p2=' + s;
    if (t1 != '' || t2 != '') {
        if (t1 == '') { alert('请选择入住时间！'); return false; }
        if (t2 == '') { alert('请选择离店时间！'); return false; }
        if (Date.parse(t1.replace(/-/g, '/')) >= Date.parse(t2.replace(/-/g, '/'))) {
            alert('入住时间必须大于离店时间！'); return false;
        } else if (Date.parse(d.getFullYear() + '/' + (d.getMonth() + 1) + '/' + d.getDate()) > Date.parse(t1.replace(/-/g, '/'))) {
            alert('入住时间不能小于今天！'); return false;
        }
        url += '&tm1=' + t1 + '&tm2=' + t2;
    }
    url += '&key=' + $('#key').val();
    url = url.substring(1);
    location = p + 'hotel/list/' + c + '-' + t + '-0.html?' + url;
}
function EditDate(id) {
    var obj = ($('.table[name="roomlist"]').length == 0 ? $('table[name="roomlist"][hid="' + id + '"]') : $('.table[name="roomlist"][hid="' + id + '"]'))
    obj.html('<tr><td><img src="' + webpath + 'sys/images/loading.gif"/></td></tr>')
    GetRoom(obj, $('#tm1_' + id).val(), $('#tm2_' + id).val());
}
function SendHotelSms(ID) {
    if (GetCookie('username') == '') { ShowWindow('', 'alertlogin', webpath + 'alertlogin.aspx'); return; }
    $.get(webpath + "sys/ajax/hotel/SendAddress.ashx", { id: ID }, function (data) { if (data != 'ok') { alert(data); } else { alert('发送成功!'); } }, 'text');
}
$(document).ready(function () {
    //入住时间
    GetRoom(($('.table[name="roomlist"]').length == 0 ? $('table[name="roomlist"]') : $('.table[name="roomlist"]')), '', '');
    $('[name="tm1"]').each(function () {
        var today = new Date(Date.parse(webconfig().date.replace(/-/g, '/')));
        today = Date.parse(today.getFullYear() + '/' + (today.getMonth() + 1) + '/' + today.getDate());
        var t2 = '#tm2' + $(this).attr('id').replace('tm1', ''), d, d1;
        var l1 = parseInt($(this).attr('l')), l2 = parseInt($(t2).attr('l'));
        if (!l1) l1 = 1;
        if (!l2) l2 = 1;
        var minadvance = webconfig().hotel.minadvance, maxadvance = webconfig().hotel.maxadvance;
        var mindate, maxdate;
        mindate = today + 86400000 * minadvance;
        maxdate = mindate + 86400000 * maxadvance;
        var tmp = $(this).attr('mindate'), tmp1 = $(this).attr('maxdate');
        if (tmp == undefined) tmp = '2000-1-1';
        if (tmp1 == undefined) tmp1 = '2100-1-1';
        tmp = Date.parse(tmp.replace(/-/g, '/'));
        tmp1 = Date.parse(tmp1.replace(/-/g, '/'));
        if (mindate < tmp) mindate = tmp;
        if (maxdate > tmp1) maxdate = tmp1;
        $(this).datepicker({ minDate: new Date(mindate), maxDate: new Date(maxdate), numberOfMonths: l1, onSelect: function (dateText, inst) {
            var t2 = $('#tm2' + $(this).attr('id').replace('tm1', ''));
            var d = Date.parse(dateText.replace(/-/g, '/'));
            var maxbooking = webconfig().hotel.maxbooking;
            maxbooking = (maxbooking == undefined ? 30 : parseInt(maxbooking));
            t2.datepicker('option', 'minDate', new Date(d + 86400000)).datepicker('option', 'maxDate', new Date(d + 86400000 * maxbooking));
            setTimeout('$(\'#tm2' + $(this).attr('id').replace('tm1', '') + '\').datepicker("show")', 10);
        }
        });
        var maxbooking = webconfig().hotel.maxbooking;
        mindate = Date.parse($(this).val().replace(/-/g, '/')) + 86400000;
        maxdate = mindate + 86400000 * (maxbooking - 1);
        tmp1 += 86400000;
        if (maxdate > tmp1) maxdate = tmp1;
        $(t2).datepicker({ minDate: new Date(mindate), maxDate: new Date(maxdate), numberOfMonths: l2, onClose: function (dateText, inst) {
            if ($(this).attr('fu'))
                setTimeout('eval(\'' + $(this).attr('fu') + '\');', 10);
        }
        });
    });
    $('#tjHotel>.skin1').each(function () { $(this).mouseover(function () { $('#tjHotel>.skin1').show(); $('#tjHotel>.skin2').hide(); $(this).hide(); $(this).next('.skin2').show(); }); }); $('#tjHotel>.skin1:first').mouseover();

    //满意度
    $('[hotelreviewss]').each(function () {
        var r = parseInt($(this).attr('hotelreviewss'));
        var h = parseInt($(this).attr('haoping'));
        $(this).html((r == 0 ? 100 : Math.round(h / r * 100)) + '%');
    });
});